/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.bus.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.bus.entity.Entinfo;
import com.thinkgem.jeesite.modules.bus.service.EntinfoService;

/**
 * 企业基本信息维护功能Controller
 * @author Zhang Xingliang
 * @version 2020-06-25
 */
@Controller
@RequestMapping(value = "${adminPath}/bus/entinfo")
public class EntinfoController extends BaseController {

	@Autowired
	private EntinfoService entinfoService;
	
	@ModelAttribute
	public Entinfo get(@RequestParam(required=false) String id) {
		Entinfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = entinfoService.get(id);
		}
		if (entity == null){
			entity = new Entinfo();
		}
		return entity;
	}
	
	@RequiresPermissions("bus:entinfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(Entinfo entinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Entinfo> page = entinfoService.findPage(new Page<Entinfo>(request, response), entinfo); 
		model.addAttribute("page", page);
		return "modules/bus/entinfoList";
	}

	@RequiresPermissions("bus:entinfo:view")
	@RequestMapping(value = "form")
	public String form(Entinfo entinfo, Model model) {
		model.addAttribute("entinfo", entinfo);
		return "modules/bus/entinfoForm";
	}

	@RequiresPermissions("bus:entinfo:edit")
	@RequestMapping(value = "save")
	public String save(Entinfo entinfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, entinfo)){
			return form(entinfo, model);
		}
		entinfoService.save(entinfo);
		addMessage(redirectAttributes, "保存企业基本信息成功");
		return "redirect:"+Global.getAdminPath()+"/bus/entinfo/?repage";
	}
	
	@RequiresPermissions("bus:entinfo:edit")
	@RequestMapping(value = "delete")
	public String delete(Entinfo entinfo, RedirectAttributes redirectAttributes) {
		entinfoService.delete(entinfo);
		addMessage(redirectAttributes, "删除企业基本信息成功");
		return "redirect:"+Global.getAdminPath()+"/bus/entinfo/?repage";
	}

}